package com.hxy.websocket.controller;

import com.hxy.websocket.service.WebSocketServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
public class SystemController {
    @Resource
    private WebSocketServer webSocketServer;

    @RequestMapping("sys/healthCheck")
    public String healthCheck() {
        return "健康";
    }

    @RequestMapping("sys/sendMsg")
    public String sendMsg(@RequestParam("msg") String msg) {
       webSocketServer.sendToAllClient("这是来自服务端的消息：" + msg + "\t\t\t" + DateTimeFormatter.ofPattern("HH:mm:ss:SSS").format(LocalDateTime.now()));
       return "success";
    }
}
